package com.zd.miko.tally.MVP.ModuleTallyDetail

import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.View
import android.view.ViewGroup
import android.widget.RelativeLayout
import com.zd.miko.tally.R
import com.zd.miko.tally.Utils.Utils
import kotlinx.android.synthetic.main.activity_tally_detail.*

/**
 * 这个类有两种打开方式，编辑以及展示
 * */
class TallyDetailActivity : AppCompatActivity() {

    val MODEL_EDIT = 0
    val MODEL_SHOW = 1
    var type = MODEL_EDIT

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_tally_detail)
        initToolbar()
        initType()

        initShowImage()
    }

    private fun initShowImage() {
        val res = intent.getIntExtra("res", 0)
        val name = intent.getStringExtra("name")
        if (res != 0) {
            item_iv.setBackgroundResource(res)
            item_tv.text = name
        }
    }

    private fun initType() {
        type = intent.getIntExtra("type", MODEL_EDIT)
        if (type == MODEL_EDIT) {
            bt_delete.visibility = View.GONE
            bt_edit.visibility = View.GONE
        } else {
            bt_complete.visibility = View.GONE
        }
    }


    private fun initToolbar() {
        rlToolbar.setBackgroundColor(this.resources.getColor(R.color.editToolbar))

        val params1 = RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                Utils.dpToPx(56))
        params1.setMargins(0, Utils.getStatusBarHeight(), 0, 0)

        toolbar.layoutParams = params1

        setSupportActionBar(toolbar)
        supportActionBar!!.setDisplayShowTitleEnabled(false)
        supportActionBar!!.setDisplayHomeAsUpEnabled(true)
    }
}
